package com.woniuxy.user.service.impl;


import com.woniuxy.user.entity.User;
import com.woniuxy.user.mapper.UserMapper;
import com.woniuxy.user.service.CustomUserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: Mr·Xiang
 * @create 2023-11-06 11:50
 */
@Service
public class CustomUserDetailsServiceImpl implements CustomUserDetailsService {
    @Resource
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {

        User user = userMapper.findByAccount(account);

        if (user == null){
            throw new UsernameNotFoundException("账号不存在");
        }

        return user;
    }
}
